package nc.impl.single.pub;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

import nc.bs.dao.BaseDAO;
import nc.bs.framework.common.NCLocator;
import nc.bs.hr.utli.BaseDAOUtliJM;
import nc.itf.single.pub.IPrivateUtilMaintain;
import nc.itf.uap.pf.IPFBusiAction;
import nc.md.persist.framework.IMDPersistenceService;
import nc.ui.pub.pf.PfUtilClient;
import nc.ui.scm.plugin.InvokeEventProxy;
import nc.vo.pi.InvoiceVO;
import nc.vo.pub.AggregatedValueObject;
import nc.vo.pub.BusinessException;
import nc.vo.pub.SuperVO;
import nc.vo.pub.lang.UFBoolean;
import nc.vo.pub.lang.UFDate;
import nc.vo.pub.pf.PfUtilWorkFlowVO;

public class PrivateUtilMaintainImpl implements IPrivateUtilMaintain{


	public String executeInsert__RequiresNew(SuperVO vo) throws BusinessException {
		BaseDAO dao = new BaseDAO();
		return dao.insertVO(vo);
	}


	public int executeUpdate__RequiresNew(SuperVO vo) throws BusinessException {
		
		BaseDAO dao = new BaseDAO();
		return dao.updateVO(vo);
	}
	

	public String[] executeInsert__RequiresNew(SuperVO[] vos) throws BusinessException {
		BaseDAO dao = new BaseDAO();
		return dao.insertVOArray(vos);
	}


	public int executeUpdate__RequiresNew(SuperVO[] vos) throws BusinessException {
		BaseDAO dao = new BaseDAO();
		return dao.updateVOArray(vos);
	}


	public int executeDelete__RequiresNew(String funcode, String createdate) throws BusinessException {
		BaseDAO dao = new BaseDAO();
		return dao.executeUpdate("delete from smg_pay1_log where funcode='"+funcode+"' and createdate='"+createdate+"'");
	}
	public int executeDelete__RequiresNew(String sql) throws BusinessException {
		BaseDAO dao = new BaseDAO();
		return BaseDAOUtliJM.getBase().executeUpdate(sql);
	}

	public Object invoicSAVEBASE__RequiresNew(String actionName,
			String billType, String currentDate, PfUtilWorkFlowVO wfContextVO,
			AggregatedValueObject billvo, Object userObj, HashMap eParam)
			throws BusinessException {

		NCLocator.getInstance().lookup(IPFBusiAction.class).processAction(actionName, billType, currentDate, wfContextVO, billvo, userObj, eParam);
		
		return null;
	}


	public Object invoicAPPROVE__RequiresNew(String actionName,
			String billType, String currentDate, PfUtilWorkFlowVO wfContextVO,
			AggregatedValueObject billvo, Object userObj, HashMap eParam)
			throws BusinessException {
		NCLocator.getInstance().lookup(IPFBusiAction.class).processAction(actionName, billType, currentDate, wfContextVO, billvo, userObj, eParam);
		
		return null;
	}


	public Object invoicDELETE__RequiresNew(InvoiceVO billvo)
			throws Exception {
//		 PfUtilClient.processBatch("DISCARD", nc.vo.scm.pu.BillTypeConst.PO_INVOICE,null,
//		            new InvoiceVO[] {
//			 billvo
//		            }, new Object[] {
//		              null
//		            });
//		nc.bs.pi.InvoiceDMO dmo = new nc.bs.pi.InvoiceDMO();
//	      dmo.delete(billvo);
		UFDate dCurrenDate = new UFDate(new Date());
		String currentDate = dCurrenDate.toString().substring(0, 10);
		ArrayList<Object> userObj = new ArrayList<Object>();
		userObj.add(null);
		userObj.add(null);
		ArrayList thirdList = new ArrayList();
		thirdList.add(dCurrenDate);
		thirdList.add(UFBoolean.FALSE);
		thirdList.add(UFBoolean.FALSE);
		userObj.add(thirdList);
		userObj.add(0);
		userObj.add("cvendormangid");
		HashMap<String, String> hmPfExParams = new HashMap<String, String>();
		hmPfExParams.put("nosendmessage", "nosendmessage");
		hmPfExParams.put("notechecked", "notechecked");
		NCLocator.getInstance().lookup(IPFBusiAction.class).processAction("DISCARD", "25", currentDate, null, billvo, userObj, hmPfExParams);
		 //new InvokeEventProxy("pu", "25", null).beforeAction(nc.vo.scm.plugin.Action.DELETE, new AggregatedValueObject[]{billvo});
		return null;
	}
}
